import 'package:dio/dio.dart';
import 'package:xiaofanshu_flutter/model/response.dart';

import '../utils/request.dart';

class AuthApi {
  static String prefix = "/auth";

  /// 登录
  static Future<HttpResponse> loginByPassword(
      String phoneNumber, String password) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/login",
      method: DioMethod.post,
      params: {"phoneNumber": phoneNumber, "password": password},
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse> loginByCode(
      String phoneNumber, String code) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/loginByCode",
      method: DioMethod.post,
      params: {"phoneNumber": phoneNumber, "smsCode": code},
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse> logout(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/logout",
      method: DioMethod.post,
      isShowLoading: true,
      params: {'userId': userId},
    ));
  }

  static Future<HttpResponse> register(
      String email, String password, String code) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/register",
      method: DioMethod.post,
      data: {"email": email, "password": password, "code": code},
      isShowLoading: true,
    ));
  }

  // 获取TRTC的userSig
  static Future<HttpResponse> getTrtcUserSig(String userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getTrtcUserSig",
      method: DioMethod.post,
      params: {"userId": userId},
    ));
  }
}

class StoryMapApi {
  static String prefix = "/notes/storymap";

  /// 获取聚合数据
  static Future<HttpResponse> getClusters(int zoom, String bounds, {
    int? clusterRadius,
    List<String>? categories,
    bool? isOfficial,
    String? nickname,
  }) async {
    // 构建参数字典
    Map<String, dynamic> params = {
      "zoom": zoom,
      "bounds": bounds,
      if (clusterRadius != null) "clusterRadius": clusterRadius,
      if (isOfficial != null) "isOfficial": isOfficial,
      if (nickname != null && nickname.isNotEmpty) "nickname": nickname,
    };
    
    // 添加分类参数（数组形式）
    if (categories != null && categories.isNotEmpty) {
      params['categories'] = categories;
    }
    
    return HttpResponse.fromJson(await Request().request(
      "$prefix/clusters",
      method: DioMethod.get,
      params: params,
    ));
  }

  /// 获取边界内故事数据
  static Future<HttpResponse> getStoriesWithinBounds(String bounds, {
    List<String>? categories,
    bool? isOfficial,
    String? nickname,
    bool? isRoute
  }) async {
    // 构建参数字典
    Map<String, dynamic> params = {
      "bounds": bounds,
      if (isOfficial != null) "isOfficial": isOfficial,
      if (nickname != null && nickname.isNotEmpty) "nickname": nickname,
      if (isRoute != null) "isRoute": isRoute,
    };
    
    // 添加分类参数（数组形式）
    if (categories != null && categories.isNotEmpty) {
      params['categories'] = categories;
    }
    
    return HttpResponse.fromJson(await Request().request(
      "$prefix/withinBounds",
      method: DioMethod.get,
      params: params,
    ));
  }
  
  
}

class UserApi {
  static String prefix = "/user";

  static Future<HttpResponse> getUserInfo(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getUserInfo",
      method: DioMethod.get,
      params: {"userId": userId},
    ));
  }

  /// 获取用户会员信息
  static Future<HttpResponse> getMemberInfo(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getMemberInfo",
      method: DioMethod.get,
      params: {"userId": userId},
    ));
  }

  static Future<HttpResponse> updateUserAvatar(String avatar, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateAvatarUrl",
      method: DioMethod.post,
      data: {"id": id, "avatarUrl": avatar},
    ));
  }

  static Future<HttpResponse> updateUserBackground(
      String background, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateBackgroundImage",
      method: DioMethod.post,
      data: {"id": id, "homePageBackground": background},
    ));
  }

  static Future<HttpResponse> updateUserNickname(
      String nickname, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateNickname",
      method: DioMethod.post,
      data: {"id": id, "nickname": nickname},
    ));
  }

  static Future<HttpResponse> updateUserIntroduction(
      String introduction, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateIntroduction",
      method: DioMethod.post,
      data: {"id": id, "selfIntroduction": introduction},
    ));
  }

  static Future<HttpResponse> updateUserSex(int sex, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateSex",
      method: DioMethod.post,
      data: {"id": id, "sex": sex},
    ));
  }

  static Future<HttpResponse> updateUserBirthday(
      String birthday, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateBirthday",
      method: DioMethod.post,
      data: {"id": id, "birthday": birthday},
    ));
  }

  static Future<HttpResponse> updateUserArea(String area, int id) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateArea",
      method: DioMethod.post,
      data: {"id": id, "area": area},
    ));
  }

  static Future<HttpResponse> attentionUser(
      int userId, int targetUserId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/relation/attention",
      method: DioMethod.post,
      isShowLoading: true,
      params: {"userId": userId, "targetUserId": targetUserId},
    ));
  }

  static Future<HttpResponse> viewUserInfo(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/viewUserInfo",
      method: DioMethod.get,
      params: {"userId": userId},
    ));
  }

  static Future<HttpResponse> getAttentionList(
      int userId, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/relation/attentionList",
      method: DioMethod.get,
      params: {"userId": userId, "pageNum": page, "pageSize": size},
    ));
  }

  static Future<HttpResponse> getFansList(
      int userId, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/relation/fansList",
      method: DioMethod.get,
      params: {"userId": userId, "pageNum": page, "pageSize": size},
    ));
  }

  static Future<HttpResponse> resetPassword(
      String phoneNumber, String password, String smsCode) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/resetPassword",
      method: DioMethod.post,
      params: {
        "phoneNumber": phoneNumber,
        "password": password,
        "smsCode": smsCode,
      },
    ));
  }
}

class NoteApi {
  static String prefix = "/notes";

  static Future<HttpResponse> publishNotes(Map<String, dynamic> data) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/publish",
      method: DioMethod.post,
      data: data,
    ));
  }

  static Future<HttpResponse> getAttentionUserNotes(int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getAttentionUserNotes",
      method: DioMethod.get,
      params: {"page": page, "pageSize": size},
      // isShowLoading: true,
    ));
  }

  static Future<HttpResponse> getNoteCategory() async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/category/getNotesCategoryList",
      method: DioMethod.get,
    ));
  }

  // 旧接口（保留兼容）
  static Future<HttpResponse> getRecommendNotesList(int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getLastNotesByPage",
      method: DioMethod.get,
      params: {"page": page, "pageSize": size},
      isShowLoading: true,
    ));
  }

  // 新推荐接口 - 获取推荐列表
  static Future<HttpResponse> getRecommendNotesNew(int page, int pageSize) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getRecommendNotes",
      method: DioMethod.get,
      params: {"page": page, "pageSize": pageSize},
      isShowLoading: true,
    ));
  }

  // 标记笔记已读
  static Future<HttpResponse> markNotesAsRead(String notesId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/markNotesAsRead",
      method: DioMethod.post,
      params: {"notesId": notesId},
    ));
  }

  // 重置推荐（刷新推荐列表）
  static Future<HttpResponse> refreshRecommend() async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/refreshRecommend",
      method: DioMethod.post,
    ));
  }

  static Future<HttpResponse> getRecommendNotesListByCategory(
      int page, int size, int categoryId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getNotesByCategoryId",
      method: DioMethod.get,
      params: {
        "page": page,
        "pageSize": size,
        "categoryId": categoryId,
        "type": 0,
        "notesType": 2
      },
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse> praiseNotes(
      int notesId, int userId, int targetUserId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/praiseNotes",
      method: DioMethod.post,
      params: {
        "notesId": notesId,
        "userId": userId,
        "targetUserId": targetUserId
      },
    ));
  }

  static Future<HttpResponse> getMyNotes(
      int publishType, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getNotesByUserId",
      method: DioMethod.get,
      params: {
        "page": page,
        "pageSize": size,
        "authority": publishType,
        "type": 0
      },
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse> getNotesByView(
      int page, int size, int type, int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getNotesByView",
      method: DioMethod.get,
      params: {"page": page, "pageSize": size, "type": type, "userId": userId},
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse> getMyCollects(int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getNotesByUserId",
      method: DioMethod.get,
      params: {"page": page, "pageSize": size, "type": 1, "authority": 0},
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse> getMyLikes(int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getNotesByUserId",
      method: DioMethod.get,
      params: {"page": page, "pageSize": size, "type": 2, "authority": 0},
      isShowLoading: true,
    ));
  }

  static Future<HttpResponse>
      getAllNotesCountAndPraiseCountAndCollectCount() async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getAllNotesCountAndPraiseCountAndCollectCount",
      method: DioMethod.get,
    ));
  }

  static Future<HttpResponse> getNotesDetail(int notesId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getNotesByNotesId",
      method: DioMethod.get,
      params: {"notesId": notesId},
    ));
  }

  /// 获取文章续写信息
  static Future<HttpResponse> getNotesContinuation(int notesId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/continuation/$notesId",
      method: DioMethod.get,
    ));
  }

  /// 获取文章树形结构
  static Future<HttpResponse> getNotesTree(int notesId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/continuation/tree/$notesId",
      method: DioMethod.get,
    ));
  }

  /// 获取文章的历史内容（从根节点到当前节点的完整内容）
  static Future<HttpResponse> getHistoricalContent(int nodeId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/continuation/historical-content/$nodeId",
      method: DioMethod.get,
    ));
  }

  /// AI生成剧情
  /// [nodeId] 节点ID（续写模式必传）
  /// [sceneDescription] 场景描述/剧情内容
  /// [feedback] 反馈内容（用于重新生成）
  /// [k] K值参数（默认3）
  /// [forceRecreate] 是否强制重新生成（默认false）
  static Future<HttpResponse> generatePlot({
    int? nodeId,
    required String sceneDescription,
    String? feedback,
    int k = 3,
    bool forceRecreate = false,
  }) async {
    // 构建请求体（JSON格式）
    Map<String, dynamic> requestBody = {
      'sceneDescription': sceneDescription,
      'k': k,
      'forceRecreate': forceRecreate,
    };
    
    // 续写模式需要传nodeId
    if (nodeId != null && nodeId > 0) {
      requestBody['nodeId'] = nodeId;
    }
    
    // 如果有反馈内容则添加
    if (feedback != null && feedback.isNotEmpty) {
      requestBody['feedback'] = feedback;
    }
    
    return HttpResponse.fromJson(await Request().request(
      "$prefix/continuation/generate-plot",
      method: DioMethod.post,
      data: requestBody,  // 使用 data 参数发送 JSON 请求体
    ));
  }

  static Future<HttpResponse> collectNotes(
      int notesId, int userId, int targetUserId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/collectNotes",
      method: DioMethod.post,
      params: {
        "notesId": notesId,
        "userId": userId,
        "targetUserId": targetUserId
      },
    ));
  }

/// 保存故事路线
  static Future<HttpResponse> saveStoryRoute({
    required String routeName,
    required List<Map<String, dynamic>> stories,
    required int userId,
    String? description,
    String? routeColor,
    int? routeStyle,
    int? lineWidth,
    int? isPublic,
    int? estimatedDuration,
    List<String>? tags,
  }) async {
    // 构建节点数据
    List<Map<String, dynamic>> nodes = stories.map((story) {
      return {
        "notesId": int.tryParse(story['id']?.toString() ?? '0') ?? 0,
        "nodeType": 1, // 默认节点类型
        "customTitle": story['title']?.toString() ?? "",
        "customDescription": story['content']?.toString() ?? "",
        "stayDuration": 0, // 默认值为0
        "transportType": 1, // 默认交通方式：步行
      };
    }).toList();
    
    Map<String, dynamic> data = {
      "routeName": routeName.isNotEmpty ? routeName : "未命名路线",
      "routeDescription": description ?? "",
      "routeColor": routeColor ?? "#FF5722",
      "routeStyle": routeStyle ?? 1,
      "lineWidth": lineWidth ?? 3,
      "isPublic": isPublic ?? 1,
      "estimatedDuration": estimatedDuration ?? 0,
      "tags": tags ?? [],
      "nodes": nodes,
    };
    
    return HttpResponse.fromJson(await Request().request(
      "$prefix/routes",
      method: DioMethod.post,
      data: data,
      params: {"userId": userId},
      isShowLoading: true,
    ));
  }
  
  /// 获取用户的故事路线列表
  static Future<HttpResponse> getUserStoryRoutes({
    int page = 1,
    int pageSize = 10,
  }) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/route/list",
      method: DioMethod.get,
      params: {
        "page": page,
        "pageSize": pageSize,
      },
    ));
  }
  
  /// 删除故事路线
  static Future<HttpResponse> deleteStoryRoute(String routeId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/route/delete",
      method: DioMethod.delete,
      params: {"routeId": routeId},
      isShowLoading: true,
    ));
  }
  
  /// 获取用户创建的路线列表
  static Future<HttpResponse> getUserCreatedRoutes({
    required int userId,
    int pageNum = 1,
    int pageSize = 10,
  }) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/routes/user/$userId/created",
      method: DioMethod.get,
      params: {
        "pageNum": pageNum,
        "pageSize": pageSize,
      },
    ));
  }
  
  /// 获取路线详情
  static Future<HttpResponse> getRouteById({
    required int routeId,
    int? currentUserId,
  }) async {
    Map<String, dynamic> params = {};
    if (currentUserId != null) {
      params["currentUserId"] = currentUserId;
    }
    
    return HttpResponse.fromJson(await Request().request(
      "$prefix/routes/$routeId",
      method: DioMethod.get,
      params: params,
    ));
  }

  /// 删除路线
  static Future<HttpResponse> deleteRoute({
    required int routeId,
    required int userId,
  }) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/routes/$routeId",
      method: DioMethod.delete,
      params: {"userId": userId},
      isShowLoading: true,
    ));
  }

  /// 删除笔记
  static Future<HttpResponse> deleteNotes(int notesId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/deleteNotes",
      method: DioMethod.delete,
      params: {"notesId": notesId},
      isShowLoading: true,
    ));
  }

  /// 修改笔记
  static Future<HttpResponse> updateNotes(Map<String, dynamic> data) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/updateNotes",
      method: DioMethod.put,
      data: data,
      isShowLoading: true,
    ));
  }
}

class SearchApi {
  static String prefix = "/search";

  static Future<HttpResponse> searchUser(
      String keyword, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/user/getUser",
      method: DioMethod.get,
      params: {"keyword": keyword, "page": page, "pageSize": size},
    ));
  }

  static Future<HttpResponse> searchNotes(
      String keyword, int page, int size, int notesType, int hot) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/notes/getNotesByKeyword",
      method: DioMethod.get,
      params: {
        "keyword": keyword,
        "page": page,
        "pageSize": size,
        "notesType": notesType,
        "hot": hot
      },
    ));
  }

  static Future<HttpResponse> getNotesNearBy(
      double latitude, double longitude, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/notes/getNotesNearBy",
      method: DioMethod.post,
      data: {
        "longitude": longitude,
        "latitude": latitude,
        "page": page,
        "pageSize": size
      },
    ));
  }
}

class CommentApi {
  static String prefix = "/comment";

  static Future<HttpResponse> getCommentCountByNotesId(int notesId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getCommentCount",
      method: DioMethod.get,
      params: {"notesId": notesId},
    ));
  }

  static Future<HttpResponse> getCommentFirstListByNotesId(
      int notesId, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getCommentFirstList",
      method: DioMethod.get,
      params: {"notesId": notesId, "page": page, "pageSize": size},
    ));
  }

  static Future<HttpResponse> getCommentSecondListByNotesId(
      int notesId, String parentId, int page, int size) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/getCommentSecondList",
      method: DioMethod.get,
      params: {
        "notesId": notesId,
        "parentId": parentId,
        "page": page,
        "pageSize": size
      },
    ));
  }

  static Future<HttpResponse> praiseComment(
      String commentId, int userId, int targetUserId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/praiseComment",
      method: DioMethod.post,
      params: {
        "commentId": commentId,
        "userId": userId,
        "targetUserId": targetUserId
      },
    ));
  }

  static Future<HttpResponse> addComment(Map<String, dynamic> data) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/addComment",
      method: DioMethod.post,
      data: data,
    ));
  }

  static Future<HttpResponse> setTopComment(String commentId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/setTopComment",
      method: DioMethod.post,
      isShowLoading: true,
      params: {"commentId": commentId},
    ));
  }

  static Future<HttpResponse> deleteComment(String commentId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/deleteComment",
      method: DioMethod.delete,
      isShowLoading: true,
      params: {"commentId": commentId},
    ));
  }
  
}

class ThirdApi {
  static String prefix = "/third";

  static Future<HttpResponse> uploadImage(FormData data) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/uploadImg",
      method: DioMethod.post,
      data: data,
      reactiveTime: const Duration(seconds: 20),
    ));
  }

  static Future<HttpResponse> uploadVideo(FormData data) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/uploadVideo",
      method: DioMethod.post,
      data: data,
      reactiveTime: const Duration(seconds: 100),
    ));
  }

  static Future<HttpResponse> uploadAudio(FormData data) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/uploadAudio",
      method: DioMethod.post,
      data: data,
      reactiveTime: const Duration(seconds: 20),
    ));
  }

  // 发送登录手机验证码
  static Future<HttpResponse> sendLoginPhoneSms(String phoneNumber) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/sendLoginPhoneSms",
      method: DioMethod.get,
      params: {"phoneNumber": phoneNumber},
    ));
  }

  // 发送重置密码手机验证码
  static Future<HttpResponse> sendResetPhoneSms(String phoneNumber) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/sendResetPhoneSms",
      method: DioMethod.get,
      params: {"phoneNumber": phoneNumber},
    ));
  }

  // 获取周边信息，location 经度和纬度用","分割，经度在前，纬度在后，经纬度小数点后不得超过6位
  static Future<Map<String, dynamic>> getPeripheralInformation(
      String location, int page,
      {String keywords = ''}) async {
    Dio dio = Dio();
    
    // 如果有关键词，使用周边搜索（优先考虑location中心点）
    // 如果关键词为空，直接周边搜索
    Response response = await dio.get(
      "https://restapi.amap.com/v3/place/around",
      queryParameters: {
        "key": "ba5f42790d796d124bf2ccac2709d146",
        "location": location,
        "keywords": keywords,
        "radius": 10000,
        "page": page,
        "sortrule": "distance", // 按距离排序，确保返回离中心点最近的结果
      },
    );
    return response.data;
  }
}

class AchievementApi {
  static String prefix = "/achievement";

  /// 获取用户等级信息
  static Future<HttpResponse> getUserLevel(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/level/$userId",
      method: DioMethod.get,
    ));
  }

  /// 获取用户成就列表
  static Future<HttpResponse> getUserAchievements(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/user/$userId",
      method: DioMethod.get,
    ));
  }

  /// 获取用户经验记录
  static Future<HttpResponse> getUserExpLog(int userId, int pageNum, int pageSize) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/exp/log/$userId",
      method: DioMethod.get,
      params: {
        "pageNum": pageNum,
        "pageSize": pageSize,
      },
    ));
  }
}

/// 像素画相关API
class PixelArtApi {
  static String prefix = "/pixelart";

  /// 获取地图区域内的像素画列表
  static Future<HttpResponse> getPixelArtsInBounds({
    required double minLat,
    required double maxLat,
    required double minLng,
    required double maxLng,
  }) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/list",
      method: DioMethod.get,
      params: {
        "minLat": minLat,
        "maxLat": maxLat,
        "minLng": minLng,
        "maxLng": maxLng,
      },
    ));
  }

  /// 创建像素画
  static Future<HttpResponse> createPixelArt(Map<String, dynamic> data) async {
    return HttpResponse.fromJson(await Request().request(
      prefix,
      method: DioMethod.post,
      data: data,
    ));
  }

  /// 更新像素画
  static Future<HttpResponse> updatePixelArt(Map<String, dynamic> data) async {
    return HttpResponse.fromJson(await Request().request(
      prefix,
      method: DioMethod.put,
      data: data,
    ));
  }

  /// 删除像素画
  static Future<HttpResponse> deletePixelArt(String pixelArtId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/$pixelArtId",
      method: DioMethod.delete,
    ));
  }

  /// 获取用户的像素画列表
  static Future<HttpResponse> getUserPixelArts(int userId) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/user/$userId",
      method: DioMethod.get,
    ));
  }
}

/// 应用更新相关API
class AppUpdateApi {
  static String prefix = "/notes/app";

  /// 检查应用更新
  /// [platform] 平台：android 或 ios
  /// [versionCode] 当前版本号
  static Future<HttpResponse> checkUpdate({
    required String platform,
    required int versionCode,
  }) async {
    return HttpResponse.fromJson(await Request().request(
      "$prefix/checkUpdate",
      method: DioMethod.get,
      params: {
        'platform': platform,
        'versionCode': versionCode,
      },
    ));
  }
}
